package views;

import java.awt.BorderLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;

import presenters.ReportsPresenter;

public class ReportsPanel extends JPanel {
	private JComboBox comboBox;
	/**
	 * 
	 */
	private static final long serialVersionUID = -5683626516514015681L;
	ReportsPresenter myPresenter;
	JPanel panel;
	private String[] reports = {"Revenue Report",
								"Frequent User Report",
								"Location Preference",
								"Maintenance History Report"};
	// all of report panels added
	
	
	public ReportsPanel() {
		setLayout(new BorderLayout(0, 0));
		
		panel = new JPanel();
		add(panel, BorderLayout.CENTER);
		
		Box verticalBox = Box.createVerticalBox();
		panel.add(verticalBox);
		
		JLabel lblChooseAReport = new JLabel("Choose A Report:");
		verticalBox.add(lblChooseAReport);
		
		comboBox = new JComboBox(reports);
		comboBox.setEditable(false);
		verticalBox.add(comboBox);
		 
		
		JButton btnGenerate = new JButton("Generate");
		verticalBox.add(btnGenerate);
		btnGenerate.addActionListener(new MyActionListener());
		
		
		myPresenter = new ReportsPresenter(this);
	}
	
	private class MyActionListener implements ActionListener {

		@Override
		public void actionPerformed(ActionEvent e) {
			FreqUserReportPanel furPanel = new FreqUserReportPanel();
			RevenueReportPanel revPanel = new RevenueReportPanel();
			LocationPrefReportPanel locPanel = new LocationPrefReportPanel();
			MaintHistoryReportPanel maintPanel = new MaintHistoryReportPanel();
			String choice = String.valueOf(comboBox.getSelectedItem());
			if (choice.equals("Revenue Report"))
			{
				revPanel.getMyPresenter().generateReport();
				panel = revPanel;
				
			}
			else if (choice.equals("Location Preference"))
			{
				locPanel.getMyPresenter().generateReport();
				panel = locPanel;
				
			}
			else if (choice.equals("Frequent User Report"))
			{
				furPanel.getMyPresenter().generateReport();
				panel = furPanel;
			}
			else
			{
				maintPanel.getMyPresenter().generateReport();
				panel = maintPanel;
			}
			add(panel, BorderLayout.SOUTH);
			revalidate();			
		}
		
	}
}
